<{include file="public/header.html"}> 
	<!--问答 首页-->
	<header class="title-fixed w100 border-bottom-sm">
		<div class="title bj-white">
                    <a href="javascript:;" class="title-top title-left col-red iconfont" id="edit-back">&#xe604;</a>
                    <a href="javascript:;" class="title-right title-text col-red" id="edit-ok">完成</a>
                    <h1 class="text-center name">完善回答</h1>
		</div>
	</header>
        <div class="mt50 wd-problem" id="asking-area">
        	<h4 class="edit-title bj-grey p10"><{$item['title']}></h4>
                <input type="hidden" id="answer-info" data-wid="<{$item['wenda_id']}>" data-aid="<{$item['answer_id']}>" data-uid="<{$item['answer_uid']}>" data-type="0"/>
            <div class="p10">
                <div class="edit-box answer-editor p10" contenteditable="true"><{$item['content']}></div>
            </div>
	</div>
        <script type="text/javascript" src="/static/js/wenda-min-1.0.js"></script>
        <script type="text/javascript">
            //放弃编辑
            $("#edit-back").on("click",function(){
                layer.open({
                    content: '确认要放弃编辑吗',btn: ['确认', '取消'],yes: function(index){
                        layer.close(index);
                        history.go(-1);
                    }
                });
            });
            var flag = true;
            //完善编辑
            $("#edit-ok").on("click",function(){
                if(!_is_login()){return;}
                if(!flag){$.mvalidateTip("操作过于频繁");return;}
                var _self = $(this),_answer_content=$(".answer-editor").html(),_answer_info = $("#answer-info");
                var _answer_id=_answer_info.attr("data-aid"),_wenda_wid=_answer_info.attr("data-wid"),_type=_answer_info.attr("data-type"),params={};
                if(($.trim(_answer_content)) == ""){$.mvalidateTip("提交的回答不能为空哦");return;}
                params.answerContent=_answer_content;params.wendaId=_wenda_wid;params.answerId=_answer_id;params.type=_type;params.stampTime=Math.random();
                
                layer.open({
                    content: '确认要编辑吗',btn: ['确认', '取消'],yes: function(index){
                        layer.close(index);
                        _self.text("处理中");
                        doRequest("/ajax/ajax_modify_answer",params,true,function(data){
                            $.mvalidateTip("成功完善");
                            _self.text("完成");
                            flag = true;
                            setTimeout(function(){
                                window.location.href="<{$item['answer_url']}>";
                            },1500);
                        },function(data){
                            flag = true;
                            $.mvalidateTip(data.errorMsg);
                            _self.text("完成");
                        });
                        
                    }
                });
            });
            
        </script>
<{include file="public/footer.html"}> 